﻿@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IEventService _eventService

<MDCard>
    <DataTableCard TModel="RoleInforTableModel" Headers="_headers" ApiUrl="@(_baseUrl)" ShowAddButton="false" Title="@($"{_name}列表")" @ref="dataTableCard">
        <ButtonContent>
            <CnGalWebSite.Shared.MasaComponent.Shared.Buttons.ExportButton OnQueryAsync="@(async ()=>await dataTableCard?.QueryAllAsync())" Name="角色" Class="me-4" />
        </ButtonContent>
        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="info"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>
</MDCard>


@code {
    private bool _editDialog;
    private long _editedItemId;
    private bool _detailDialog;

    private string _baseUrl = "api/tables/ListRoles";
    private string _name = "角色";

    private List<DataTableHeader<RoleInforTableModel>> _headers = new List<DataTableHeader<RoleInforTableModel>>
    {
        new ()
          {
            Text= "Id",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(RoleInforTableModel.RealId)
          },
          new (){ Text= "名称", Value= nameof(RoleInforTableModel.Name)},
          new (){ Text= "声优", Value= nameof(RoleInforTableModel.CV)},
          new (){ Text= "别称", Value= nameof(RoleInforTableModel.AnotherNameRole)},
          new (){ Text= "性别", Value= nameof(RoleInforTableModel.Gender)},
          new (){ Text= "身材数据", Value= nameof(RoleInforTableModel.FigureData)},
          new (){ Text= "身材(主观)", Value= nameof(RoleInforTableModel.FigureSubjective)},
          new (){ Text= "生日", Value= nameof(RoleInforTableModel.Birthday)},
          new (){ Text= "发色", Value= nameof(RoleInforTableModel.Haircolor)},
          new (){ Text= "瞳色", Value= nameof(RoleInforTableModel.Pupilcolor)},
          new (){ Text= "服饰", Value= nameof(RoleInforTableModel.ClothesAccessories)},
          new (){ Text= "性格", Value= nameof(RoleInforTableModel.Character)},
          new (){ Text= "角色身份", Value= nameof(RoleInforTableModel.RoleIdentity)},
          new (){ Text= "血型", Value= nameof(RoleInforTableModel.BloodType)},
          new (){ Text= "身高", Value= nameof(RoleInforTableModel.RoleHeight)},
          new (){ Text= "兴趣", Value= nameof(RoleInforTableModel.RoleTaste)},
          new (){ Text= "年龄", Value= nameof(RoleInforTableModel.RoleAge)},
          new (){ Text= "登场游戏", Value= nameof(RoleInforTableModel.GameName)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    DataTableCard<RoleInforTableModel> dataTableCard;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    public async Task LookItem(RoleInforTableModel model)
    {
        await _eventService.OpenNewPage("https://www.cngal.org/entries/index/" + model.RealId);
    }
}
